package com.example.userregister;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.userregister.bean.WeaponInfo;
import com.google.android.gms.common.api.GoogleApiClient;

public class ShowInfoActivity extends AppCompatActivity {

    private int REQUEST_CODE = 1;
    private ProgressBar pbLife;
    private TextView tvInfoLife;
    private ProgressBar pbAttack;
    private TextView tvInfoAttack;
    private ProgressBar pbSpeed;
    private TextView tvInfoSpeed;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_info);
        //1-获取上一页传递的用户信息，并展示
        //去除注册界面传递的数据
        //数据在intent中
        final Intent intent = getIntent();//获取注册界面传递的intent
        //根据关键字取出intent的数据
        String name = intent.getStringExtra("username");
        String password = intent.getStringExtra("password");
        //Toast.makeText(this,"用户名和密码为"+name+password,Toast.LENGTH_LONG).show();
        TextView tvName = (TextView) findViewById(R.id.info_name);
        TextView tvPsw = (TextView) findViewById(R.id.info_password);
        tvName.setText("用户名：" + name);
        tvPsw.setText("密  码：" + password);
        //2-初始化进度条和文本的值为0
        //在布局设计时已经完成
        pbLife = (ProgressBar) findViewById(R.id.pb_life);
        tvInfoLife = (TextView) findViewById(R.id.tv_info_life);
        pbAttack = (ProgressBar) findViewById(R.id.pb_attack);
        tvInfoAttack = (TextView) findViewById(R.id.tv_info_attack);
        pbSpeed = (ProgressBar) findViewById(R.id.pb_speed);
        tvInfoSpeed = (TextView) findViewById(R.id.tv_info_speed);

        //3-点击按钮，跳转到商店界面---在商店购买武器
        Button btnGoShop = (Button) findViewById(R.id.btn_goshop);
        btnGoShop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到商店界面，从商店返回的时候，将武器的属性值带回
                Intent intent1 = new Intent(getApplicationContext(), ShopActivity.class);
                startActivityForResult(intent1, REQUEST_CODE);//请求返回数据
            }
        });



    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        //4-从商店返回的时候，将武器的属性值带回
        WeaponInfo weaponInfo = (WeaponInfo) data.getSerializableExtra("weapon");
        //5-根据购买的武器，更新进度条和文本框的值


        String life = tvInfoLife.getText().toString();
        int Life =Integer.parseInt(life);
        String attack = tvInfoAttack.getText().toString();
        int Attack =Integer.parseInt(attack);
        String speed = tvInfoSpeed.getText().toString();
        int Speed =Integer.parseInt(speed);
        pbLife.setProgress(weaponInfo.getLife()+Life);
        tvInfoLife.setText(weaponInfo.getLife() +Life+"" );
        pbAttack.setProgress(weaponInfo.getAttack()+Attack);
        tvInfoAttack.setText(weaponInfo.getAttack() +Attack+"" );
        pbSpeed.setProgress(weaponInfo.getSpeed()+Speed);
        tvInfoSpeed.setText(weaponInfo.getSpeed()+Speed+"" );



    }


}
